/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				NotCondition
 
Function						: 				Provides a class for holding 
												the not condition class
****************************************************************************/
package planninglanguage.conditions;

import org.jdom.Element;

import util.XMLWriter;
import base.WargusGameState;


public class NotCondition extends Condition {

	Condition m_c;

	public NotCondition(Condition a_c)
	{
		m_c=a_c;
	}
	
	public void reset()
	{
		m_c.reset();
	}
	public Condition getCondition()
	{
		return m_c;
	}
	public String toString() {
		return m_c.toString(0);
	}	
	
	public boolean test(WargusGameState a_gameState)
	{
		return !m_c.test(a_gameState);
	}
	
	public String toString(int tabs) {
		String str= super.toString(tabs);
		int i;
		
		for(i=0;i<tabs;i++) str = str + "  ";
		str = str +  "Not(\n";
		if (m_c!=null)	{
			str = str + m_c.toString(tabs+1) + "\n";
		} else {
			for(i=0;i<tabs+1;i++) str = str + "  ";
			str = str +  "null\n";
		}  
		for(i=0;i<tabs;i++) str = str + "  ";
		str = str +  ")";
		return str;
	}
	
	public void writeXML(XMLWriter w) {
		w.tag("condition type=\""+this.getClass().getSimpleName()+"\"");
		{
			m_c.writeXML(w);
		}
		w.tag("/condition");
	}
	
	protected static Condition loadConditionFromXML(Element e) {
		return new NotCondition(
				Condition.loadFromXML(e.getChild("condition")));
	}
}
